/*
  - validateLogin.js
  - v0.01
  - 3/23/2011
  - 
  - Form validation for login page. 
 */

function validateLogin(){
	var flag = 0;
	var Username =  document.getElementById('username');
	var Password =  document.getElementById('password');

	if(checkEmpty(Username)) flag=1;
	if(checkEmpty(Password)) flag=1;

	if(checkUsername(Username))flag=1;
	if(checkPassword(Password))flag=1;
	
	if(flag == 1) {
		printError("Login","Invalid username/password."); 
		return false;
	}

	return true;
}

function printError(elem,str){		
		document.getElementById("error"+elem).innerHTML = str;		
}

function checkEmpty(elem){
	if(elem.value == "") return true;
	return false;
}

function checkUsername(elem){
	var ck_username = /^[A-Za-z0-9_]{6,30}$/;
	
	if (ck_username.test(elem.value)) return false;
	
	return true;	
}

function checkPassword(elem){
	var ck_password =  /^[A-Za-z0-9!@#$%^&*()_]{1,50}$/;
	
	if (ck_password.test(elem.value)) return false;
	
	return true;	
}